﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using 深入浅出WPF_BookDemo.UserController;

namespace 深入浅出WPF_BookDemo.Views
{
    /// <summary>
    /// Chapter11Window.xaml 的交互逻辑
    /// </summary>
    public partial class Chapter11Window : Window
    {
        public Chapter11Window()
        {
            InitializeComponent();
            InitializeWeatherList();
        }

        private void InitializeWeatherList()
        {
            List<Weather> weathers = new List<Weather>()
            {
                new Weather() { City = "大冯",Status = "Sunny",Date = DateTime.Now},
                new Weather() { City = "大伦",Status = "Rainy",Date = DateTime.Now},
                new Weather() { City = "启东",Status = "Foggy",Date = DateTime.Now},
                new Weather() { City = "崇川",Status = "Sunny",Date = DateTime.Now}
            };

            foreach (Weather weather in weathers)
            {
                WeatherListItemView view = new WeatherListItemView();
                view.Weather = weather;
                this.listBoxWeather.Items.Add(view);
            }

        }

        private void listBoxWeather_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            WeatherListItemView view = e.AddedItems[0] as WeatherListItemView;
            if (view != null)
            {
                this.detailView.Weather = view.Weather;
            }
        }
    }

    public class Weather
    {
        public string City { get; set; }

        public string Status { get; set; }

        public string Temperature { get; set; }

        public DateTime Date { get; set; }
    }

}
